package com.dpteam.dao.impl;

import com.dpteam.dao.NewsDao;
import com.dpteam.model.News;
import com.dpteam.util.Page;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: luolei
 * Date: 2016/1/8
 * Time: 9:12
 */
@Repository
public class NewsDaoImpl extends BaseDaoImpl<News> implements NewsDao {

    @Override
    public List<News> findByTitle(String title) {
        String hql = "from News where title like ? order by id ";
        return find(hql, "'%" + title + "%'");
    }

    @Override
    public List<News> findByTitleByPage(String title, Page page) {
        String hql = "from News where title like ? order by id ";
        return find(hql, page, "'%" + title + "%'");
    }

    @Override
    public List<News> findAll() {
        String hql = "from News order by id ";
        return find(hql);
    }

    @Override
    public List<News> findAllByPage(Page page) {
        String hql = "from News order by id ";
        return find(hql,page);
    }

    @Override
    public void deleteById(int id) {
        News news = get(News.class, id);
        if (news != null) {
            delete(news);
        }
    }
}
